<?php
/**
 * Description of SfDataHelper
 *
 * convert to symfony data format
 *
 * @author ben
 */
class SfDataHelper {
    public static $_instance=null;

    public static function getInstance() {
        $class = __CLASS__;
        if(is_null(self::$_instance)) {
            self::$_instance = new $class();
        }
        return self::$_instance;
    }

    /*
     * convert wac hash data to symfony select data
     * e.g.
     * Array
       (
         [浆染厂] => Array
         (
            [0] => Array
                (
                    [key] => 7
                    [value] => 浆染厂1
                )

            [1] => Array
                (
                    [key] => 12
                    [value] => 浆染厂2
                )

        )
     * )
     *
     * to
     *
     * array(
            "浆染厂" => array(
                 "7"=>"浆染厂1",
                 "12"=>"浆染厂2"
                )
        );

     */
    public function toSelectOptions($wacHashItems)
    {
        $resultArr = array();
        if(is_array($wacHashItems) && count($wacHashItems)>0)
        {
            foreach($wacHashItems as $itemKey=>$pairs){
                if(count($pairs)>0){
                    $tmpArr = array();
                    foreach($pairs as $pair){
                        $tmpArr[$pair["key"]] = $pair["value"];
                    }
                    $resultArr[$itemKey] = $tmpArr;
                }                
            }
        }
        return $resultArr;
    }

}

